双击PDB文件用Pymol打开

使用 macOS 自动操作(Automator) 来创建一个 .app,使 .pdb 文件在双击时用 /opt/anaconda3/bin/pymol 打开,并且支持多开 PyMOL。以下是完整的步骤:


步骤 1:创建 Shell 脚本

  1. 打开终端 (Terminal)

  2. 创建 open_pymol.sh 文件

    nano ~/open_pymol.sh
    
  3. 在文件中添加以下内容

    #!/bin/bash
    nohup /opt/anaconda3/bin/pymol "$@" >/dev/null 2>&1 &
    disown
    

    解释

    • nohup 让进程独立运行,不受终端关闭影响。
    • "$@" 代表传递所有参数,即 .pdb 文件路径。
    • >/dev/null 2>&1 & 让进程后台运行,不输出信息。
    • disown 让 PyMOL 进程与 shell 脱钩,支持多开。
  4. 保存文件

    • Ctrl + X,然后按 Y,最后按回车。
  5. 赋予执行权限

    chmod +x ~/open_pymol.sh
    

步骤 2:使用 Automator 创建 macOS App

  1. 打开 Automator

    • Cmd + Space,搜索 Automator 并打开。
  2. 创建新文档

    • 选择 “应用程序” (Application),然后点击 选择 (Choose)
  3. 添加“运行 Shell 脚本”

    • 在 Automator 左侧搜索 “运行 Shell 脚本” (Run Shell Script),然后拖到右侧的工作区域。
  4. 修改 Shell 脚本设置

    • Shell:选择 /bin/bash
    • 传递输入 (Pass input):选择 作为参数 (as arguments)
  5. 在文本框中输入以下内容

    ~/open_pymol.sh "$@"
    
  6. 保存 Automator 应用

    • 点击 文件 (File) > 另存为 (Save)
    • 取名为 PyMOL Launcher
    • 存放在 /Applications/ 目录或 ~/Applications/
    • 格式 (File Format) 选择 “应用程序” (Application)

步骤 3:设置 .pdb 文件默认打开方式

  1. 找到一个 .pdb 文件
  2. 右键 > 显示简介 (Get Info)
  3. 在“打开方式” (Open With) 选择 PyMOL Launcher.app
  4. 点击“全部更改” (Change All)

测试